package ru.troyanov.Datchick.services;

import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import ru.troyanov.Datchick.models.Sensor;
import ru.troyanov.Datchick.repositories.SensorsRepositories;

import java.util.Optional;

@Service
@Transactional(readOnly = true)
public class SensorsService {
    private final SensorsRepositories sensorsRepositories;

    public SensorsService(SensorsRepositories sensorsRepositories) {
        this.sensorsRepositories = sensorsRepositories;
    }

    public Optional<Sensor> findByName(String name) {
        return sensorsRepositories.findByName(name);
    }

    @Transactional
    public void save(Sensor sensor) {
        sensorsRepositories.save(sensor);
    }
}
